package cn.xiaolang.thread.threadlocal;

import java.util.concurrent.TimeUnit;

/**
 * 父子线程传值(子线程获取不到父线程的值)
 *
 * @author Dean
 * @date 2021-01-20
 */
public class ParentChildPassValueIssue {

    private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {

        threadLocal.set("dean");

        new Thread(() -> {
            System.out.println("子线程获取到的值：" + threadLocal.get());
        }).start();

        System.out.println("父线程获取到的值：" + threadLocal.get());

        TimeUnit.SECONDS.sleep(3);
        threadLocal.remove();

    }
}
